<template>
    <rx-dialog @handOk="handleSubmit" @cancel="cancel">
        <rx-layout>
            <div slot="center">
                <a-alert
                    message="你在GitLab至少需要代码仓库的「Maintainer」权限。否则在关联代码仓时，系统无法自动创建Jenkins流水线。"
                    type="info"
                    show-icon
                />
                <a-form-model layout="vertical" ref="form"  :model="mdl" :rules="rules" >
                    <a-form-model-item  label="GitURL" prop = "url">
                        <a-input placeholder="请输入GitURL" v-model="mdl.url"/>
                    </a-form-model-item>
                    <a-form-model-item  label="用户名" prop = "username">
                        <a-input placeholder="请输入用户名" v-model="mdl.username"/>
                    </a-form-model-item>
                    <a-form-model-item  label="密钥" prop = "secret">
                        <a-input-password placeholder="请输入密钥" v-model="mdl.secret"/>
                    </a-form-model-item>
                </a-form-model>
            </div>
        </rx-layout>
    </rx-dialog>
</template>
<script>
import SysGitManageApi from "@/api/system/core/sysGitManage.js";
import {RxDialog, BaseFormModel,Util} from '@lowcode/jpaas-common-lib';

export default {
    name: 'SysGitManageEdit',
    props: {
        appId: {
            type: String,
            default: ""
        },
        isDialog:{
            type: Boolean,
            default: false
        }
    },
    mixins: [BaseFormModel],
    components: {
        RxDialog,
    },
    data() {
        return {
            rules: {
                url: [{ required:true,message: "请输入GitURL", trigger: 'change' }],
                username: [{ required:true,message: "请输入用户名", trigger: 'change' }],
                secret: [{ required:true,message: "请输入密钥", trigger: 'change' }],
            },
            state:false
        }
    },
    created(){
        if(this.isDialog && this.appId){
           SysGitManageApi.getByAppId(this.appId).then(res=>{
               if (res && res.success && res.data) {
                   this.mdl = res.data;
               }
           });
        }
    },
    methods: {
        get(id) {
            return SysGitManageApi.get(id);
        },
        save() {
            //新增 且为应用的devops打开情况
            if(this.appId){
                this.mdl.appId = this.appId;
            }
            return SysGitManageApi.save(this.mdl);
        }
    }
}
</script>
<style scoped>

</style>
